package com.software.form.shippmentinfo.dao;

import java.util.List;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.software.form.bookingform.dao.BookingForm;

public class ShippmentInfoDaoImpl extends JdbcDaoSupport implements ShippmentInfoDao {
	public ShippmentInfo queryByNo(String no){
		ShippmentInfoMappingQuery query = new ShippmentInfoMappingQuery();
		query.setDataSource(getDataSource());
		
		String sql = " select * from shippmentinfo where bookingNo='"+no+"' ";
		query.setSql(sql);
		query.compile();
		List<ShippmentInfo> list = query.execute(new Object[]{});
		if(list.size()>0)
			return list.get(0);
		else
			return null;
	}
	public List<ShippmentInfo> queryByEmail(String agentEmail){
		ShippmentInfoMappingQuery query = new ShippmentInfoMappingQuery();
		query.setDataSource(getDataSource());
		
		String sql = " select * from shippmentinfo where agentEmail='"+agentEmail+"' ";
		query.setSql(sql);
		query.compile();
		return query.execute(new Object[]{});
	}
	public boolean add(ShippmentInfo si) {
		// TODO Auto-generated method stub
		try{
			String sql = " insert into shippmentinfo ( agentEmail, info, bookingNo )" +
			" values ( ?, ?, ? ) ";
			getJdbcTemplate().update(sql, new Object[]{si.getAgentEmail(),si.getInfo(),si.getBookingNo()});
		}catch(Exception se){
			return false;
		}
		return true;
	}
}
